import request from './config'

// 刷新token
export function refreshToken() {
  return request({
    url: '/auth/custom/refresh',
    method: 'post',
    headers: {
      Authorization: `Bearer ${getToken()}`,
    },
  })
}
// 保存token到localStorage
export function setToken(token) {
  localStorage.setItem('token', token)
}

// 从localStorage获取token
export function getToken() {
  return localStorage.getItem('token')
}

// 移除token
export function removeToken() {
  localStorage.removeItem('token')
}

export function getUserInfo() {
  const userInfo = localStorage.getItem('user_info')
  return userInfo ? JSON.parse(userInfo) : null
}
